import React, { Component } from 'react'
import { Form, Input, Button, InputNumber, Select, } from 'antd'
import userinfo from '../../mobx/userinfo';
import { UpdataNurs, QueryNurse } from "../../utils/api";
export const areas = [
    {
        title: "妇科",
        value: "妇科",
    },
    {
        title: "儿科",
        value: "儿科",
    },
    {
        title: "助产科",
        value: "助产科",
    },
    {
        title: "急诊科",
        value: "急诊科",
    },
    {
        title: "精神科",
        value: "精神科",
    },
];
export const academic = [
    {
        title: "中专学历",
        value: "中专学历",
    },
    {
        title: "专科学历",
        value: "专科学历",
    },
    {
        title: "本科学历",
        value: "本科学历",
    },
    {
        title: "硕士学历",
        value: "硕士学历",
    },
    {
        title: "博士学历",
        value: "博士学历",
    },
];
const layout = {
    labelCol: { span: 8 },
    wrapperCol: { span: 16 },
};
const validateMessages = {
    required: "${label} 为必填项!",
    types: {
        age: "${label} is not validate age!",
        number: "${label} is not a validate number!",
    },
    number: {
        range: "${label} must be between ${min} and ${max}",
    },
};
export default class Demo extends Component {
    handleOk = () => {
        userinfo.getVisible(false)
    };
    render() {
        let { list } = this.props
        const onFinish = (values) => {
            values._id = list._id
            UpdataNurs(values).then(res => {
                if (res.type) {
                    QueryNurse().then(res => {
                        userinfo.getList(res.result)
                        userinfo.getVisible(false)
                    })
                }
            })
        }

        return (
            <Form
                {...layout}
                onFinish={onFinish}
                validateMessages={validateMessages}
                style={{ width: "200px" }}
                
            >
                <Form.Item
                    name="name"
                    label="姓名"
                    initialValue={list.name}
                >
                    <Input style={{ width: "400px" }} />
                </Form.Item>
                <Form.Item
                    name="age"
                    label="年龄"
                    initialValue={list.age}
                    rules={[{ type: "number", min: 0, max: 99 }]}
                >
                    <InputNumber style={{ width: "180px" }} />
                </Form.Item>
                <Form.Item
                    name="profession"
                    label="专业"
                    initialValue={list.profession}
                    rules={[{ type: "string", min: 0, max: 99 }]}
                >
                    <Input style={{ width: "400px" }} />
                </Form.Item>
                <Form.Item
                    name="education"
                    label="学历"
                    rules={[
                        {
                            required: true,
                            message: "Please select your habitual residence!",
                        },
                    ]}
                >
                    <Select placeholder="请选择学历">
                        {academic.map((item, i) => {
                            return (
                                <Select.Option value={item.title} key={i}>
                                    {" "}
                                    {item.title}{" "}
                                </Select.Option>
                            );
                        })}
                    </Select>
                </Form.Item>
                <Form.Item
                    label="科室"
                    name="office"
                    rules={[{ required: true, message: "请选择科室" }]}
                >
                    <Select placeholder="请选择">
                        {areas.map((item, i) => {
                            return (
                                <Select.Option value={item.value} key={i}>
                                    {" "}
                                    {item.title}{" "}
                                </Select.Option>
                            );
                        })}
                    </Select>
                </Form.Item>

                <Form.Item
                    name="phone"
                    label="联系方式"
                    initialValue={list.phone}
                    rules={[{ type: "string", min: 0, max: 99 }]}
                >
                    <Input style={{ width: "400px" }} />
                </Form.Item>
                <Form.Item
                    name="address"
                    label="地址"
                    initialValue={list.address}
                    rules={[{ type: "string", min: 0, max: 99 }]}
                >
                    <Input style={{ width: "400px" }} />
                </Form.Item>
                <Form.Item
                    wrapperCol={{ ...layout.wrapperCol, offset: 8 }}
                    style={{ width: "350px" }}
                ></Form.Item>
                <Form.Item
                    wrapperCol={{ ...layout.wrapperCol, offset: 8 }}
                    style={{ width: "350px" }}
                >
                    <Button type="primary" htmlType="submit">
                        提交
              </Button>
                    <Button
                        onClick={() => {
                            this.handleOk();
                        }}
                    >
                        退出
              </Button>
                </Form.Item>
            </Form>
        )
    }
}
